﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HNCDataSetTableAdapters;

public partial class UserControl_content_home : System.Web.UI.UserControl
{
    CategoryTableAdapter cate = new CategoryTableAdapter();
    ProductsTableAdapter pro = new ProductsTableAdapter();

    HNCData data = new HNCData();
    HNCDataContext hnc = new HNCDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            loadAbout();
            loadTopproduct();
        }
    }

    public void loadAbout()
    {
        //int ProductID = int.Parse(HttpContext.Current.Request.RequestContext.RouteData.Values["ProductID"].ToString());

        DataTable dt = pro.GetProductByCateID(2);
        imgImage.Alt = FuntionHNC.GetLanguage(dt.Rows[0]["Title"].ToString(), dt.Rows[0]["Title_en"].ToString());
        imgImage.Src = "~/UserUploads/Product/" + dt.Rows[0]["Image"].ToString();
        lblTitle.Text = FuntionHNC.GetLanguage(dt.Rows[0]["Title"].ToString(), dt.Rows[0]["Title_en"].ToString());
        ltrContent.Text = FuntionHNC.GetLanguage(FuntionHNC.Catchuoi(FuntionHNC.RemoveHtmlTagsUsingCharArray(dt.Rows[0]["Content"].ToString()), 100), FuntionHNC.Catchuoi(FuntionHNC.RemoveHtmlTagsUsingCharArray(dt.Rows[0]["Content_en"].ToString()), 100));
    }

    public void loadTopproduct()
    {
        List<Product> tem = new List<Product>();

        List<Category> cate = HNCData.GetAllCategoryByParentID(3);
        foreach (Category item in cate)
        {
            //var dm2 = from a in hnc.Categories
            //          where a.ParentID == item.CateID
            //          select a;
            //List<Category> cate2 = dm2.ToList<Category>();

            List<Category> cate2 = HNCData.GetAllCategoryByParentID(item.CateID).ToList<Category>();

            foreach (Category item2 in cate2)
            {
                List<Product> pro = HNCData.GetAllProductByCateID(item2.CateID);
                foreach (Product item3 in pro)
                {                  
                    Product obj = HNCData.GetOne(item3.ProductID);
                    if (obj != null)
                    {
                        tem.Add(obj);
                    }
                }
            }
        }

        var sapxep = (from a in tem 
                      where a.Status == true && a.Vip == true && a.Delete == false
                      orderby a.Order ascending, a.Editdate descending
                      select a).Take(8);

        Repeater1.DataSource = sapxep;
        Repeater1.DataBind();
    }


}